package com.yb0os1.controller.user;

import com.yb0os1.constant.StatusConstant;
import com.yb0os1.entity.Setmeal;
import com.yb0os1.result.Result;
import com.yb0os1.serve.SetmealServe;
import com.yb0os1.vo.DishItemVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController("userSetmealController")
@RequestMapping("/user/setmeal")
@Tag(name = "套餐处理的类")
@Slf4j
public class SetmealController {
    @Autowired
    private SetmealServe setmealServe;

    @Operation(summary = "根据分类id查询套餐")
    @GetMapping("/list")
    @Cacheable(cacheNames = "setmeal",key = "#categoryId")
    public Result<List<Setmeal>> list(Long categoryId) {
        Setmeal setmeal = Setmeal.builder()
                .categoryId(categoryId)
                .status(StatusConstant.ENABLE)
                .build();
        List<Setmeal> setmeals = setmealServe.list(setmeal);
        log.info("{}",setmeals);
        return Result.success(setmeals);
    }

    @Operation(summary = "根据套餐id查询包含的菜品")
    @GetMapping("/dish/{id}")
    public Result<List<DishItemVO>> getDishsBySetmealId(@PathVariable Long id) {
        List<DishItemVO> dishItemVO = setmealServe.getDishsBySetmealId(id);
        log.info("dishItemVO{}",dishItemVO);
        return Result.success(dishItemVO);
    }
}
